﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EquipmentMasterForm.aspx.cs"
    Inherits="FX.CC.Andon.WebSite.BasicDataManage.EquipmentMasterForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>设备管理</title>
    <script src="../lib/boot.js" type="text/javascript"></script>
</head>
<body>
    <div class="mini-splitter" style="width: 100%; height: 100%;">
        <div size="30%" showcollapsebutton="true">
            <div class="mini-fit">
                <div id="grid1" class="mini-datagrid" style="width: 100%; height: 100%;" idfield="WSID"
                    borderstyle="border:0;" sizelist="[5,10,20,50]" pagesize="20" onselectionchanged="onSelectionChanged"
                    selectonload="true">
                    <div property="columns">
                        <div type="indexcolumn">
                        </div>
                        <div field="LineCode" width="70" headeralign="center" allowsort="true">
                            产线编号</div>
                        <div field="LineName" width="140" headeralign="center" allowsort="true">
                            产线名称</div>
                    </div>
                </div>
            </div>
        </div>
        <div size="70%" showcollapsebutton="true">
            <div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
                <table style="width: 100%;">
                    <tr>
                        <td style="width: 100%;">
                            设备编号：<input id="EqCode" class="mini-textbox" emptytext="请输入设备编号" style="width: 150px;"
                                onenter="onKeyEnter" />
                            设备名称：<input id="EqName" class="mini-textbox" emptytext="请输入设备名称" style="width: 150px;"
                                onenter="onKeyEnter" />
                            <a class="mini-button" iconcls="icon-search" onclick="search()">查 询</a> <a class="mini-button"
                                iconcls="icon-reset" onclick="reset()">重 置</a>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
                <a class="mini-button" iconcls="icon-add" onclick="add();" plain="true">添加</a> <a
                    class="mini-button" iconcls="icon-edit" onclick="edit()" plain="true">编辑</a>
                <span class="separator"></span><a class="mini-button" id="import" iconcls="icon-import"
                    onclick="importEq();" plain="true">导入</a> <a class="mini-button" href="../ExcleTemplate/设备模板.xls"
                        id="download" iconcls="icon-download" plain="true">Excel模板</a><span class="separator"></span><a
                            class="mini-button" iconcls="icon-freeze" onclick="freeze()" plain="true">禁用</a>
                <a class="mini-button" iconcls="icon-unfrozen" onclick="unfrozen()" plain="true">启用</a>
                <span class="separator"></span><a class="mini-button" onclick="close()" iconcls="icon-close"
                    plain="true">关闭</a>
            </div>
            <div class="mini-fit">
                <div id="grid2" class="mini-datagrid" style="width: 100%; height: 100%;" idfield="EqID"
                    borderstyle="border:0;" sizelist="[10,20,50,100]" pagesize="20" onrowdblclick="ondoubleclick()">
                    <div property="columns">
                        <div type="indexcolumn">
                        </div>
                        <div field="RecStatus" width="50" headeralign="center" allowsort="true" renderer="onRecStatusRenderer">
                            状态
                        </div>
                        <div field="EqCode" width="100" headeralign="center" allowsort="true">
                            设备编号
                        </div>
                        <div field="EqName" width="140" headeralign="center" allowsort="true">
                            设备名称
                        </div>
                        <div field="EqDesc" width="120" headeralign="center" allowsort="false">
                            备注
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript">
    mini.parse();
    var grid1 = mini.get("grid1");
    var grid2 = mini.get("grid2");
    grid1.setUrl("../service/BasicDataManageHandler.ashx?action=GetLineList&RecStatus=1");
    grid1.load();
    function onSelectionChanged(e) {
        var gridWorkShop = e.sender;
        var record = gridWorkShop.getSelected();
        if (record) {
            grid2.setUrl("../Service/BasicDataManageHandler.ashx?action=GetEquipmentListById");
            grid2.load({ LineID: record.LineID });
        }
        else {
            grid2.clearRows();
        }
    }

    function add() {
        mini.open({
            url: "BasicDataManage/EquipmentInfoForm.aspx",
            title: "新增设备", width: 507, height: 305,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new" };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                grid2.reload();
            }
        });
    }
    function ondoubleclick() {
        edit();
    }
    function edit() {
        var row = grid2.getSelected();
        if (row) {
            mini.open({
                url: "BasicDataManage/EquipmentInfoForm.aspx",
                title: "编辑设备", width: 507, height: 305,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", EqID: row.EqID };
                    iframe.contentWindow.SetData(data);

                },
                ondestroy: function (action) {
                    grid2.reload();
                }
            });

        } else {
            mini.alert("请选中一条需要编辑的记录!");
        }
    }
    function importEq() {
        var row = grid1.getSelected();
        if (row) {
            mini.confirm(row.LineName + "导入Excel数据？", "你确定？",
                    function (action) {
                        if (action == "ok") {
                            mini.open({
                                url: "BasicDataManage/ImportEqForm.aspx",
                                title: row.LineName + "Excel导入", width: 408, height: 116,
                                onload: function () {
                                    var iframe = this.getIFrameEl();
                                    var data = { action: "import", LineID: row.LineID };
                                    iframe.contentWindow.SetData(data);
                                },
                                ondestroy: function (action) {
                                    grid2.reload();
                                }
                            });
                        } else {
                            return false;
                        }
                    });
        } else {
            mini.alert("请先选中左边列表中的异常明细类别名称，再导入！");
        }
    }
    function freeze() {
        var rows = grid2.getSelected();
        if (rows) {
            if (rows.RecStatus == true) {
                mini.confirm("您确定禁用:" + rows.EqName + "？", "确定？",
                    function (action) {
                        if (action == "ok") {
                            $.ajax({
                                url: "../service/PublicHandler.ashx?action=Freeze&table=UT_Equipment&field=EqID&value=" + rows.EqID,
                                success: function (text) {
                                    grid2.reload();
                                },
                                error: function () {
                                }
                            });
                        } else {
                            return false;
                        }
                    });
            }
            else {
                mini.alert(rows.EqName + " 当前状态已经是：已禁用!");
            }

        } else {
            mini.alert("请选中一条您需要禁用的记录!");
        }
    }

    function unfrozen() {
        var rows = grid2.getSelected();
        if (rows) {
            if (rows.RecStatus == false) {
                mini.confirm("您确定启用:" + rows.EqName + "？", "确定？",
                    function (action) {
                        if (action == "ok") {
                            $.ajax({
                                url: "../service/PublicHandler.ashx?action=Unfrozen&table=UT_Equipment&field=EqID&value=" + rows.EqID,
                                success: function (text) {
                                    grid2.reload();
                                },
                                error: function () {
                                }
                            });
                        } else {
                            return false;
                        }
                    });
            }
            else {
                mini.alert(rows.EqName + " 当前状态已经是：已启用!");
            }

        } else {
            mini.alert("请选中一条您需要启用的记录!");
        }
    }
    function CloseWindow(action) {
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }

    function close() {
        CloseWindow("close");
    }
    function onRecStatusRenderer(e) {
        if (e.value == "0") { return "<span style=\"color: Red;font-weight:bold;\">已禁用</span>"; }
        else if (e.value == "1") { return "<span style=\"color: Green;font-weight:bold;\">已启用</span>"; }
        else { return ""; }
    }
    function onKeyEnter(e) {
        search();
    }
    function search() {
        var EqCode = mini.get("EqCode").getValue();
        var EqName = mini.get("EqName").getValue();
        var row = grid1.getSelected();
        grid2.load({ EqCode: EqCode, EqName: EqName, WSID: row.WSID });
    }
    function reset() {
        mini.get("EqCode").setValue("");
        mini.get("EqName").setValue("");
    }
</script>
</html>
